<template>
    <div>
        <van-field label="用户名" placeholder="请输入用户名" v-model="form.name"/>
        <van-field label="密码" placeholder="请输入密码" v-model="form.password"/>
        <van-button @click="login">登录</van-button>
    </div>
</template>

<script>
import axios from 'axios'
    export default {
        data(){
            return{
                form:{}
            }
        },
        methods:{
            login(){
                axios({url:'login',method:'post',data:this.form})
                .then(res=>{
                    localStorage.setItem('userid',res.data.userid)
                    localStorage.setItem('name',res.data.username)
                    localStorage.setItem('token',res.data.token)
                    let pagelist = res.data.pagelist
                    if(pagelist.length>0){
                        pagelist=JSON.stringify(pagelist)
                    }
                    localStorage.setItem('pagelist',pagelist)
                })
            },
        },
        mounted(){}
    }
</script>

<style scoped>

</style>